package com.hazardSoft.eStore.integration;

import java.util.List;

import com.hazardSoft.eStore.common.exception.SystemException;
import com.hazardSoft.eStore.common.integration.EJB3ServiceLocator;
import com.hazardSoft.eStore.ejb.ShoppingCarEJB;
import com.hazardSoft.eStore.entities.Bill;
import com.hazardSoft.eStore.entities.Sale;
import com.hazardSoft.eStore.interfaces.ShoppingCarLocal;
import com.hazardSoft.eStore.utils.PathConstants;

public class ShoppingCarDelegate {

	private static final String CLASS_NAME = PathConstants.DELEGATES_PATH+ShoppingCarDelegate.class.getSimpleName();
	private ShoppingCarLocal shoppingCarLocal;
	
	public ShoppingCarDelegate() throws SystemException{
		
		try {
			shoppingCarLocal = (ShoppingCarLocal) EJB3ServiceLocator.getLocalEJB(ShoppingCarEJB.EJB_NAME);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "shoppingCarDelegate");
		}
	}
	
	public void addProduct(Sale sale) throws SystemException {
		
		try {
			shoppingCarLocal.addProduct(sale);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "addProducts");
		}
	}

	
	public Bill buyProducts(Bill bill) throws SystemException {
		
		try {
			return shoppingCarLocal.buyProducts(bill);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "buyProducts");
		}
	}

	
	public List<Sale> listProducts() throws SystemException {
		
		try {
			return shoppingCarLocal.listProducts();
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "listProducts");
		}
	}

	
	public void removeProduct(Sale sale) throws SystemException {
		
		try {
			shoppingCarLocal.removeProduct(sale);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "removeProduct");
		}
	}

	
	public void setProducts(List<Sale> sales) throws SystemException {
		
		try {
			shoppingCarLocal.setProducts(sales);
		} catch (Exception e) {
			throw new SystemException(e, CLASS_NAME, "setProducts");
		}
	}
	
	
}
